package com.todo.strategy.pipeline.application.handler.Pstrategy;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.service.api.pipeline.request.EnablePStrategyDetailRequest;
import com.todo.strategy.online.service.api.pipeline.request.UpdatePStrategyDetailRequest;
import com.todo.strategy.pipeline.application.entity.context.MemoOperateActionContext;
import com.todo.strategy.pipeline.application.entity.context.PStrategyOperateActionContext;
import com.todo.strategy.pipeline.application.handler.memo.AbstractMemoOperateHandle;
import com.todo.strategy.pipeline.application.remote.PStrategyPipelineRemoteService;
import com.todo.strategy.pipeline.common.enums.OperateActionEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/3/1 05:50
 * @description
 */
@Slf4j
@Component
public class PStrategyUpdateHandler extends AbstractPStrategyOperateHandle {

    @Resource
    private PStrategyPipelineRemoteService pStrategyPipelineRemoteService;

    @Override
    protected Boolean doActionHandle(PStrategyOperateActionContext context) {
        UpdatePStrategyDetailRequest request = new UpdatePStrategyDetailRequest();
        request.setBusinessId(context.getBusinessId());
        request.setOriginData(context.getOriginData());
        request.setEnableVersion(context.getEnableVersion());
        request.setCurrentVersion(context.getCurrentVersion());
        BizResponse<Boolean> bizResponse = pStrategyPipelineRemoteService.updatePStrategyDetail(request);
        if (bizResponse == null || !bizResponse.isSuccess() || !bizResponse.getData()) {
            return false;
        }
        return true;
    }

    @Override
    protected Boolean match(PStrategyOperateActionContext context) {
        if (context.getOperateActionEnum().equals(getStrategyActionEnum())) {
            return true;
        }
        return false;
    }

    @Override
    protected OperateActionEnum getStrategyActionEnum() {
        return OperateActionEnum.UPDATE;
    }
}
